
//encodeURI()中文编码  decodeURI()中文解码

//添加cookie，times的单位是分钟
function setCookie(key, value, times) {
    var date = new Date();
    if(times != null){
        date.setTime(date.getTime() + times*60*1000);
        document.cookie = key + '=' + encodeURI(value) + ';expires=' + date.toGMTString();
    }else{
        document.cookie = key + '=' + encodeURI(value);
    }
}

//获取cookie(指定key的内容)
function getCookie(key) {
    let newCookie = decodeURI(document.cookie).split(';');
    for(var i = 0;i < newCookie.length; i++){
        let addCookie = newCookie[i].split('=');
        if(key == addCookie[0]){
            return addCookie[1]
        }
    }
}

//删除cookie
function delCookie(key, value) {
    setCookie(key, null, -1);
}

//删除cookie，可以通过key和value来判断，也可以只通过key来判断